package com.qf.openapi.web.master.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;

/*
 * 该vo类用于定义通用的返回json的字段
 * */
public class ResultVo extends HashMap {
    /**
     * 该方法用于返回通用成功的json
     *
     * @return
     */
    public static ResultVo ok() {
        ResultVo resultVo = new ResultVo();
        resultVo.put("code", 1);
        resultVo.put("msg", "ok");
        return resultVo;
    }

    public static ResultVo ok(Object user) {
        ResultVo resultVo = new ResultVo();
        resultVo.put("code", 1);
        resultVo.put("msg", "ok");
        resultVo.put("data",user);
        return resultVo;
    }

    /**
     * 该方法用于通用的错误的json
     *
     * @return
     */
    public static ResultVo error() {
        ResultVo resultVo = new ResultVo();
        resultVo.put("code", -1);
        resultVo.put("msg", "error");
        return resultVo;
    }

    /**
     * 该方法用于通用的错误的json,接收自定义的错误消息
     *
     * @return
     */
    public static ResultVo error( String msg) {
        ResultVo resultVo = new ResultVo();
        resultVo.put("code", -1);
        resultVo.put("msg", msg);
        return resultVo;
    }
}
